#include("../../comm/ListHead.html")
<div class="layui-fluid layui-anim layui-anim-scale">
    <div class="layui-row layui-col-space5">
        <div class="layui-col-md12 height-auto">
            <div class="layui-card">
                <div class="card-search SearchTable">
                    <p style="float:right">
                        <input type="text" id="search_deptid" lay-verify="required" placeholder="部门ID" autocomplete="off"
                               class="table-search-text width120">
                        <input type="text" id="search_deptname" lay-verify="required" placeholder="部门名" autocomplete="off"
                               class="table-search-text width200">
                        <button class="layui-btn layui-btn-warm layui-btn-sm" lay-event="DoSearch">
                            搜索
                        </button>
                    </p>
                    <i class="layui-icon layui-icon-slider"></i>
                    当前位置 > <span class="color_green">系统部门列表</span>
                </div>
                <div class="layui-card-body">
                    <table class="layui-hide" id="table_1" lay-filter="table_1"></table>

                    <script type="text/html" id="table_1_bar_title">
                        <div class="layui-btn-container">
                            <button class="layui-btn layui-btn-sm btn-add" lay-event="AddSystemDept">
                                <i class="layui-icon">&#xe608;</i> 添加新部门
                            </button>
                            <button class="layui-btn layui-btn-sm layui-btn-disabled" permission-one="btn-edit" lay-event="EditSystemDept">修改</button>
                            <button class="layui-btn layui-btn-sm layui-btn-disabled" permission-one="btn-del" lay-event="DelSystemDept">删除</button>
                        </div>
                    </script>

                    <script type="text/html" id="table_1_bar1">
                        <a class="layui-btn layui-btn-xs btn-edit" lay-event="edit">修改部门</a>
                    </script>
                </div>
            </div>
        </div>
    </div>
</div>

<script language="JavaScript">
    layui.use(['myTable', 'table', 'form', 'util', 'myTool'], function () {
        table = layui.table;
        myTable = layui.myTable;
        myTool = layui.myTool;
        form = layui.form;
        var $ = layui.$;
        tableindex = myTable.render({
            elem: '#table_1', skin: 'line'
            , url: 'SysDeptListApi'
            , toolbar: '#table_1_bar_title'
            , title: '系统部门列表'
            , cols: [[
                {type: 'checkbox', width: 36}
                , {field: 'dept_id', title: '部门编号', width: 120, align: 'center'}
                , {field: 'sindex', title: '顺序', width: 90, align: 'center', sort: true, edit: 'text'}
                , {field: 'dept_name', title: '部门名称', width: 180}
                , {field: 'dept_desc', title: '说明', hide: false}
                , {fixed: 'right', title: '操作', toolbar: '#table_1_bar1', width: 120, align: 'center'}
            ]]
            , page: true
            , limit: 10
            , serviceSort: true, initSort: {field: 'sindex', type: 'asc'}
            , editField: {url: 'ModifySystemDeptFieldApi', key: 'dept_id'}
        });

        //搜索 和重载
        layui.util.event("lay-event", {
            SearchReload: function () {
                tableindex.reload({});
            },
            DoSearch: function () {
                tableindex.reload({
                    where: {
                        like: {dept_name: $("#search_deptname").val()},
                        s: {dept_id: $("#search_deptid").val()}
                    }
                    , page: {curr: 1}
                });
            }
        });

        //头工具栏事件
        table.on('toolbar(table_1)', function (obj) {
            myTool.toolbar(this, obj, {
                AddSystemDept: function () {
                    index = top.layer.open({
                        type: 2, offset: '10vh', area: ['800px', '550px'], title: ['添加部门', 'font-size:15px;'],
                        content: ["sysdept/AddSystemDept", 'no'],
                        end: function () {
                            tableindex.reload();
                        }
                    });
                }
                , EditSystemDept: function () {
                    layui.myTool.doSingleSelect(table.checkStatus('table_1'), {}, function (data) {
                        index = top.layer.open({
                            type: 2, offset: '10vh', area: ['800px', '550px'], title: ['修改部门', 'font-size:15px;'],
                            content: ["sysdept/EditSystemDept?dept_id=" + data[0].dept_id, 'no'],
                            end: function () {
                                tableindex.reload();
                            }
                        });
                    });
                }
                , DelSystemDept: function () {
                    layui.myTool.doSingleSelect(table.checkStatus('table_1'), {}, function (data, keys) {
                        index = top.layer.confirm('你是否确认删除部门【' + data[0].dept_name + '】', {icon: 3, title: '提示', offset: '100px'}, function (index2) {
                            layui.myTool.post("DelSystemDeptApi", {dept_id: data[0].dept_id}, function () {
                                top.layer.close(index2);
                                tableindex.reload();
                            });
                        });
                    });
                }
            });
        });

        //监听行工具事件
        table.on('rowDouble(table_1)', function (obj) {
            top.layer.open({
                type: 2, offset: '10vh', title: ['修改部门信息', 'font-size:15px;'],
                area: ['800px', '550px'],
                content: ["sysdept/EditSystemDept?dept_id=" + obj.data.dept_id, 'no'],
                end: function () {
                    tableindex.reload();
                }
            });
        });
        //监听行工具事件
        table.on('tool(table_1)', function (obj) {
            var data = obj.data;
            if (obj.event === 'edit') {//修改部门信息
                index = top.layer.open({
                    type: 2, offset: '10vh', title: ['修改部门信息', 'font-size:15px;'],
                    area: ['800px', '550px'],
                    content: ["sysdept/EditSystemDept?dept_id=" + data.dept_id, 'no'],
                    end: function () {
                        tableindex.reload();
                    }
                });
            }
        });
    });
</script>
</body>
</html>


